package com.example.a26436.newpractise.practise2;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.example.a26436.newpractise.R;


import java.util.List;

/**
 * Created by 26436 on 2020/9/20.
 */

public class BannerAdapter extends PagerAdapter {
    private List<BannerEnity.DataBean>mlist;
    private Context mContext;

    public BannerAdapter(List<BannerEnity.DataBean> mlist, Context mContext) {
        this.mlist = mlist;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

//实例化条目
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_vp_banner_adapter_, null, false);
        ImageView ivBanner = inflate.findViewById(R.id.iv_banner_vp_banner_adpter);
        String imagePath = mlist.get(position).getImagePath();
        Glide.with(mContext).load(imagePath).into(ivBanner);
        container.addView(inflate);
        return inflate;

    }
//销毁条目
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }
}
